﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace Seagull.Shell
{
    static class Extensions
    {
        [DebuggerNonUserCode]
        public static void BeginInvoke(this Control control, Action action)
        {
            try
            {
                control.BeginInvoke(action);
            }
            catch (InvalidOperationException)
            {
                // 可能是窗口已关闭
            }
        }

        public static void SetColor(this ToolStripProgressBar progressBar)
        {
            if(progressBar.Value < 60)
            {
                progressBar.ForeColor = Color.Lime;
            }
            else if(progressBar.Value < 80)
            {
                progressBar.ForeColor = Color.Yellow;
            }
            else
            {
                progressBar.ForeColor = Color.Red;
            }
        }
    }
}
